<?php


namespace App\Http\Controllers\Web;


use App\Http\Controllers\BaseController;
use App\Services\MaterialService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;

class MaterialController extends BaseController
{
    protected $service;

    public function __construct(Request $request, MaterialService $commonService)
    {
        parent::__construct($request);
        $this->service = $commonService;
    }

    public function index()
    {
        $results = $this->service->select($this->request->all());
        $rules = $this->service->getQueryCondition();
        if ($this->request->isMethod('post')) {
            return View::make('material.content', $results);
        } else {
            return View::make('material.query', array_merge($results, ['rules' => $rules]));
        }
    }

    public function detail()
    {
        $this->request->validate([
            'id' => 'required'
        ], [
            'id.required' => 'id原料不能为空！'
        ]);
        $results = $this->service->getDetail($this->request->all());

        return view('material.report')->with($results);
    }
}
